﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using sharp_net.Repositories;
using zkdao.Enum;

namespace zkdao.Domain {

    public class Tag : DomainGuid, IAggregateRoot {

        [Required]
        [MaxLength(200)]
        public string Name { get; set; }

        public int GroupEnum { get; set; }

        public eTagGroup Group {
            get { return (eTagGroup)GroupEnum; }
        }

        public virtual ICollection<Rebate> Rebates { get; set; }

        public void Update(TagData data) {
            if (!string.IsNullOrEmpty(data.Name))
                this.Name = data.Name;
            if (data.GroupEnum != 0)
                this.GroupEnum = data.GroupEnum;
            if (data.ActEnum != 0)
                this.ActEnum = data.ActEnum;
            if (data.Rebates != null && data.Rebates.Count != 0) {
                if (Rebates == null)
                    Rebates = new List<Rebate>();
                foreach (var item in data.Rebates) {
                    this.Rebates.Add(Mapper.Map<RebateData, Rebate>(item));
                }
            }
        }
    }

    public class TagData : DomainGuidData {

        public string Name { get; set; }

        public int GroupEnum { get; set; }

        public virtual ICollection<RebateData> Rebates { get; set; }
    }
}